package algotithm.acwing.rangeofproblems.test907;

/**
 * @author zhouyanxiang
 * @Date 2021-01-2021/1/29-14:43
 * @Title 907. 区间覆盖
 */
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

        String[] num = reader.readLine().split(" ");
        int s = Integer.parseInt(num[0]);
        int t = Integer.parseInt(num[1]);

        int n = Integer.parseInt(String.valueOf(reader.readLine()));


        ArrayList<int[]> list = new ArrayList<>();
        while (n-- > 0) {
            String[] num2 = reader.readLine().split(" ");
            int[] arr = new int[2];
            arr[0] = Integer.parseInt(num2[0]);
            arr[1] = Integer.parseInt(num2[1]);
            list.add(arr);
        }

        list.sort(new Comparator<int[]>(){
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[0] - o2[0];
            }
        });

        int res = 0;
        boolean flag = false;
        for (int i = 0; i < list.size(); i++) {
            int j = i, r = Integer.MIN_VALUE;
            while (j < list.size() && list.get(j)[0] <= s) {
                r = Math.max(r,list.get(j)[1]);
                j++;
            }
            if (r < s) {
                res = -1;
                break;
            }
            res++;

            if (r >= t) {
                flag = true;
                break;
            }
            s = r;
            i = j - 1;
        }
        if (!flag) {
            res = -1;
        }
        writer.write(res + "\n");
        writer.flush();
        writer.close();
        reader.close();
    }

}
